<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script>
    const arr = [{name: "wang", age: 12}, {name: "zhang", age: 19}, {name: "sun", age: 29}]
    // 1.splice  给数组中插入一个元素
    const liu = {name: "liu", age: 18}
    arr.splice(1, 1, liu)
    console.log(arr)

    // 2.map  ["wang-12", "zhang-19, "sun-29"]
    const arr2 = arr.map(item => item.name + "-" + item.age)
    console.log(arr2)


    // 3.reduce
    let ages = 0
    arr.forEach(item => ages += item.age)
    console.log(ages)


    arr.reduce((pre, current) => pre + current.age, 0)

  </script>
</body>
</html>
